#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(hidbase, 0.0.5, [SounOS@gmail.com])
AC_CONFIG_SRCDIR([src/dbase.h])
AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE

# Checks for programs.
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_LIBTOOL

# Checks for libraries.
# FIXME: Replace `main' with a function in `-lm':
AC_CHECK_LIB([m], [main])
# FIXME: Replace `main' with a function in `-lsbase':
AC_CHECK_LIB([sbase], [main])
# FIXME: Replace `main' with a function in `-lz':
AC_CHECK_LIB([z], [main])

# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h fcntl.h locale.h stdlib.h string.h sys/mount.h sys/param.h sys/time.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM

# Checks for library functions.
AC_FUNC_FORK
AC_FUNC_LSTAT
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_FUNC_MKTIME
AC_FUNC_MMAP
AC_FUNC_REALLOC
AC_TYPE_SIGNAL
AC_FUNC_STAT
AC_CHECK_FUNCS([ftruncate gettimeofday memset mkdir munmap setlocale strcasecmp strchr strdup strerror strncasecmp])

#check pthread 
havepthread=no
AC_CHECK_LIB(pthread,pthread_create,havepthread=yes)
if test "$havepthread" = "yes" ; then
    CPPFLAGS="${CPPFLAGS} -DHAVE_PTHREAD"
    LDFLAGS="${LDFLAGS} -lpthread"
    LIBS="${LIBS} -lpthread"
fi

#semaphore
#havesemaphore=no
#AC_CHECK_LIB(c, sem_timedwait, havesemaphore=yes)
#if test "$havesemaphore" = "yes" ; then
#        CPPFLAGS="${CPPFLAGS} -DHAVE_SEMAPHORE"
#fi

#check mmap
havemmap=no
AC_CHECK_LIB(c, munmap, havemmap=yes)
if test "$havemmap" = "yes" ; then
    CPPFLAGS="${CPPFLAGS} -DHAVE_MMAP"
fi
#AC_CHECK_EXTRA_OPTIONS

AC_CONFIG_FILES([Makefile
                 doc/Makefile
                 src/Makefile])
AC_OUTPUT
